package com.ruoyi.web.controller.fund;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.balanceReturn.domain.HouseReturnT;
import com.ruoyi.data.MD5;
import com.ruoyi.door.domain.HouseDoorT;
import com.ruoyi.refund.domain.HouseRefundT;
import com.ruoyi.returnQuery.service.IHouseReturnQueryTService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 返还Controller
 * 
 * @author lijie
 * @date 2023-05-04
 */
@RestController
@RequestMapping("/fund/returnQuery")
public class HouseReturnQueryTController extends BaseController
{
    @Autowired
    private IHouseReturnQueryTService houseReturnQueryTService;

    /**
     * 查询返还列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseReturnT houseReturnT) throws Exception {
        startPage();
        if(houseReturnT.getUserName()!=null){
            houseReturnT.setUserName(MD5.encrypt(houseReturnT.getUserName()));
        }
        List<HouseReturnT> list = houseReturnQueryTService.selectHouseReturnTList(houseReturnT);
        for(HouseReturnT houseReturnVO:list){
            houseReturnVO.setUserName(MD5.decrypt(houseReturnVO.getUserName()));
        }
        if(list.size()>0){
            HouseReturnT houseReturnVO = houseReturnQueryTService.selectHouseReturnSum(houseReturnT);
            houseReturnVO.setAreaName("合计");
            list.add(houseReturnVO);
        }
        return getDataTable(list);
    }

    /**
     * 导出返还列表
     */
   @Log(title = "返还", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseReturnT houseReturnT) throws Exception {
        if(houseReturnT.getUserName()!=null){
            houseReturnT.setUserName(MD5.encrypt(houseReturnT.getUserName()));
        }
        List<HouseReturnT> list = houseReturnQueryTService.selectHouseReturnTList(houseReturnT);
       for(HouseReturnT houseReturnVO:list){
           houseReturnVO.setUserName(MD5.decrypt(houseReturnVO.getUserName()));
       }
        if(getDataTableSumJudge(list)){
            HouseReturnT houseReturnVO = houseReturnQueryTService.selectHouseReturnSum(houseReturnT);
            houseReturnVO.setAreaName("合计");
            list.add(houseReturnVO);
        }
        ExcelUtil<HouseReturnT> util = new ExcelUtil<HouseReturnT>(HouseReturnT.class);
        util.exportExcel(response, list, "返还数据");
    }

    /**
     * 获取返还详细信息
     */
    @GetMapping(value = "/{returnId}")
    public AjaxResult getInfo(@PathVariable("returnId") Long returnId)
    {
        return AjaxResult.success(houseReturnQueryTService.selectHouseReturnTByReturnId(returnId));
    }

     @GetMapping(value = "getNote/{costId}")
    public AjaxResult getNote(@PathVariable("costId") Long costId)
    {
        HouseReturnT houseReturnVO = houseReturnQueryTService.selectHouseReturnNote(costId);
        return AjaxResult.success(houseReturnVO);
    }


}


